//
//  PzPublicConst.swift
//  Pz
//
//  Created by 蓝鳍互娱 on 2024/6/27.
//

import Foundation
import UIKit
final class PzPublicConst {
    /// 是否是刘海屏（notch screen）
    static let isLiuHaiScreen: Bool = {
        var window: UIWindow? = UIApplication.shared.currentUIWindow()
        
        guard let unwrapedWindow = window else{
            return false
        }
        if unwrapedWindow.safeAreaInsets.left > 0 || unwrapedWindow.safeAreaInsets.bottom > 0 {
            return true
        }
       return false
    }()
  
    static let safeAreaInsets: UIEdgeInsets = {
        if #available(iOS 13, *) {
            return UIApplication.shared.currentUIWindow()?.safeAreaInsets ?? UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
        } else {
            return UIApplication.shared.windows.first?.safeAreaInsets ?? UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
        }
    }()
    
    
    static let ScreenRatio: CGFloat = PzPublicConst.ScreenWidth/750.0
    /// 屏宽
    static let ScreenWidth = UIScreen.main.bounds.size.width
    /// 屏高
    static let ScreenHeight = UIScreen.main.bounds.size.height
    
    static let ScreenNavBarHeight: CGFloat = 88
    
    /// 状态栏高度
    static let ScreenStatusBarHeight: CGFloat  = {
        let statusManager = UIApplication.shared.windows.first?.windowScene?.statusBarManager
        return statusManager?.statusBarFrame.height ?? 40.0
    }()
    
    /// 导航栏+状态栏高度
    static let ScreenNavStatusBarHeight: CGFloat = {
        return ScreenStatusBarHeight + ScreenNavBarHeight
    }()
//    /// 底部tabBar高度
//    static let ScreenTabbarHeight: CGFloat = {
//        return isLiuHaiScreen ? 34 + 49 : 49
//    }()
//    
    /// 底部高度
    static let ScreenBottomSpaceHeight: CGFloat = {
        return isLiuHaiScreen ? 68 : 0
    }()
    /// 顶部高度
    static let ScreenTopSpaceHeight: CGFloat = {
        return isLiuHaiScreen ? 88 : 40
    }()
    
    //
    static let photoNowTime: TimeInterval = {
        let currentDate = NSDate()
        let currentTime = currentDate.timeIntervalSince1970
        return currentTime
    }()
    static let ScreenBundld: String = {
        return "com.fqzjz.ac"
    }()
    
    static let photoLivePriceUrl: String = {
        return "http://fuqin.zjz.ogv8oe.top/lbbserves/api/appdingyue/info"
    }()
    static let photoLiveFaceUrl: String = {
        return "http://fuqin.zjz.ogv8oe.top/zhengjianzhao/api/detectLiveFaceAccurate"
    }()
    static let photoLiveKoutuUrl: String = {
        return "http://fuqin.zjz.ogv8oe.top/zhengjianzhao/api/koutu"
    }()
    static let photoLiveUploadUrl: String = {
        return "http://fuqin.zjz.ogv8oe.top/zhengjianzhao/api/uploaduserfileinfo"
    }()
    static let photoLiveSaveUrl: String = {
        return "http://fuqin.zjz.ogv8oe.top/zhengjianzhao-serve"
    }()
    static let photoLiveEditUrl: String = {
        return "http://fuqin.zjz.ogv8oe.top/zhengjianzhao-serve/h5/editPhoto.html?id=%@&isen=false"
    }()
    static let photoLiveAllPhotoUrl: String = {
        return "http://fuqin.zjz.ogv8oe.top/zhengjianzhao-serve/h5/allPhoto.html?isen=false&id=%@"
    }()
    static let photoLiveMaidianUrl: String = {
        return "http://fuqin.zjz.ogv8oe.top/lbbmajiabao/api/maidian"
    }()
    
    static let photoUserAgreementUrl: String = {
        return "https://lgg69az5eh.feishu.cn/docx/UJKSd3qnAoe5loxCoLWcGia5nEf?from=from_copylink"
    }()
    static let photoPriveAgreementUrl: String = {
        return "https://lgg69az5eh.feishu.cn/docx/J9r4dOiohoeKWJxlnc2cRwW0nhc?from=from_copylink"
    }()
}

extension UIApplication {
    
    /// 找到当前展示的window
    func currentUIWindow() -> UIWindow? {
        if #available(iOS 13.0, *){
            let connectedScenes = UIApplication.shared.connectedScenes
                .filter({
                    $0.activationState == .foregroundActive})
                .compactMap({$0 as? UIWindowScene})
            
            let window = connectedScenes.first?
                .windows
                .first { $0.isKeyWindow }

            return window
        }else{
            return UIApplication.shared.windows.first
        }
    }
}
extension Int {
    func fitScale() -> Self {
        let ratio = CGFloat(self) * PzPublicConst.ScreenRatio
        return Int(ratio)
    }
}

extension Double {
    func fitScale() -> Self {
        let ratio = CGFloat(self) * PzPublicConst.ScreenRatio
        return Double(ratio)
    }
}
